package com.huawei.appgallery.common.media.widget.zoomview;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.huawei.appgallery.common.media.activity.ImagePreviewActivity;
import java.io.File;
import java.math.BigDecimal;
import o.azb;
import o.blc;
import o.ble.b;
import o.ble.j;
import o.blf;
import o.blh;
import o.blo;
import o.blp;
import o.dmi;
import o.dmp;
import o.dmq;
import o.epv;
import o.eqx;
import o.tf;
import o.zp;

@SuppressLint({"ValidFragment"})
public class PictrueFragment extends Fragment {
    private LinearLayout ʼ;
    private int ʽ;
    private LinearLayout ˊ;
    private String ˋ;
    private String ˎ;
    private blc ˏ;
    private ScaleView ॱ;
    private RelativeLayout ॱॱ;
    private int ᐝ;
    private int ﾟ;

    public static PictrueFragment ˋ(blc o_blc) {
        PictrueFragment pictrueFragment = new PictrueFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("image_bean", o_blc);
        pictrueFragment.ʼ(bundle);
        return pictrueFragment;
    }

    public void ˏ(@Nullable Bundle bundle) {
        super.ˏ(bundle);
        if (ˊॱ() != null && (ˊॱ().getSerializable("image_bean") instanceof blc)) {
            this.ˏ = (blc) ˊॱ().getSerializable("image_bean");
            if (this.ˏ != null) {
                this.ʽ = this.ˏ.ˋ();
                this.ᐝ = this.ˏ.ॱ();
                this.ˋ = this.ˏ.ˊ();
                this.ˎ = this.ˏ.ˎ();
            }
        }
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = LayoutInflater.from(ॱˋ()).inflate(j.ʼ, null);
        ˊ(inflate);
        return inflate;
    }

    private int ˋॱ(boolean z) {
        if (z) {
            return this.ﾟ;
        }
        return Integer.MIN_VALUE;
    }

    private zp ˏॱ(boolean z) {
        zp zpVar = (zp) ((zp) ((zp) new zp().ॱ(true)).ˊ(tf.ˏ)).ॱॱ();
        if (this.ᐝ <= 0 || this.ʽ <= 0) {
            blf.ˋ.ˏ("PictrueFragment", "error width");
            return zpVar;
        }
        int ˋॱ = ˋॱ(z);
        return (zp) zpVar.ˊ(ˋॱ, ˋॱ);
    }

    private void ˊ(View view) {
        this.ॱॱ = (RelativeLayout) view.findViewById(b.ˍ);
        this.ॱ = (ScaleView) view.findViewById(b.ˋˋ);
        this.ˊ = (LinearLayout) view.findViewById(b.ˊˊ);
        this.ˊ.setVisibility(8);
        this.ﾟ = blp.ˏ();
        this.ʼ = (LinearLayout) view.findViewById(b.ˋ);
        this.ʼ.setVisibility(8);
        if (!TextUtils.isEmpty(this.ˋ)) {
            ʾॱ();
        }
        ʽᐝ();
    }

    private void ʾॱ() {
        final boolean ʼᐝ = ʼᐝ();
        this.ˊ.setVisibility(0);
        blo.ˊ(this.ॱ, this.ˋ, this.ˎ, ˏॱ(ʼᐝ), new blh(this) {
            final /* synthetic */ PictrueFragment ˏ;

            public void ˏ(Object obj) {
                this.ˏ.ॱ.setHasDrawable(true);
                this.ˏ.ॱ.setVisibility(0);
                this.ˏ.ˊ.setVisibility(8);
                this.ˏ.ʼ.setVisibility(8);
                if (obj != null && (obj instanceof Drawable)) {
                    final float intrinsicWidth = (float) ((Drawable) obj).getIntrinsicWidth();
                    if (this.ˏ.ʽ <= 0 || this.ˏ.ᐝ <= 0) {
                        dmq.ˏ.ˊ(dmp.CONCURRENT, new dmi(this) {
                            final /* synthetic */ AnonymousClass1 ˋ;

                            public void run() {
                                File ˎ = eqx.ˎ(this.ˋ.ˏ.ॱ.getContext(), this.ˋ.ˏ.ˋ);
                                if (ˎ != null) {
                                    Options options = new Options();
                                    options.inJustDecodeBounds = true;
                                    BitmapFactory.decodeFile(ˎ.getAbsolutePath(), options);
                                    this.ˋ.ˏ.ˏ((float) options.outWidth, (float) options.outHeight, intrinsicWidth / ((float) options.outWidth));
                                }
                            }
                        });
                    } else if (ʼᐝ) {
                        this.ˏ.ˏ((float) this.ˏ.ʽ, (float) this.ˏ.ᐝ, intrinsicWidth / ((float) this.ˏ.ʽ));
                    } else {
                        this.ˏ.ˏ((float) this.ˏ.ʽ, (float) this.ˏ.ᐝ, 1.0f);
                    }
                }
            }

            public void ˊ() {
                this.ˏ.ʼ.setVisibility(0);
                this.ˏ.ˊ.setVisibility(8);
                this.ˏ.ॱ.setHasDrawable(false);
                this.ˏ.ॱ.setVisibility(4);
            }
        });
    }

    private void ʽᐝ() {
        OnClickListener anonymousClass4 = new OnClickListener(this) {
            final /* synthetic */ PictrueFragment ˋ;

            {
                this.ˋ = r1;
            }

            public void onClick(View view) {
                FragmentActivity ॱˋ = this.ˋ.ॱˋ();
                if (ॱˋ instanceof ImagePreviewActivity) {
                    ((ImagePreviewActivity) ॱˋ).ᐝ();
                }
            }
        };
        this.ॱ.setOnClickListener(anonymousClass4);
        this.ॱॱ.setOnClickListener(anonymousClass4);
    }

    private boolean ʼᐝ() {
        if (this.ᐝ > this.ﾟ || this.ʽ > this.ﾟ) {
            return true;
        }
        return false;
    }

    private void ˏ(float f, float f2, float f3) {
        Context ॱˊ = ॱˊ();
        if (ॱˊ != null) {
            float ॱ = ((float) azb.ॱ(ॱˊ)) / f;
            float ॱ2 = ((float) epv.ॱ(ॱˊ)) / f2;
            float min = Math.min(ॱ, ॱ2);
            ॱ = Math.max(ॱ, ॱ2);
            if (ॱ < 1.0f) {
                ॱ2 = 1.0f;
            } else {
                ॱ2 = Math.max(2.0f, new BigDecimal(1.5d).multiply(new BigDecimal((double) ॱ)).floatValue());
            }
            this.ॱ.setMaxScale(ॱ2 / f3);
            if (min < 1.0f) {
                ॱ2 = min / 2.0f;
            } else {
                ॱ2 = 1.0f;
            }
            this.ॱ.setMinScale(ॱ2 / f3);
            this.ॱ.setmFillBigScale(ॱ / f3);
            this.ॱ.setmFillSmallScale(min / f3);
            this.ॱ.setOriginScale(1.0f / f3);
        }
    }

    public void ॱ() {
        if (this.ॱ != null) {
            this.ॱ.ˎ();
        }
    }
}
